﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Diagnostics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Student> list = new List<Student>();

            Student stu0 = new Student(1, "张三", 20);
            Student stu1 = new Student(2, "张四", 18);
            Student stu2 = new Student(3, "张五", 21);
            Student stu3 = new Student(4, "张六", 19);
            Student stu4 = new Student(5, "张七", 22);
            Student stu5 = new Student(6, "张八", 23);

            list.Add(stu0);
            list.Add(stu1);
            list.Add(stu2);
            list.Add(stu3);
            list.Add(stu4);
            list.Add(stu5);

            while (true)
            {
                Console.WriteLine("1、添加学生信息 2、查询学生信息 3、删除学生信息");
                int key = int.Parse(Console.ReadLine());
                switch (key)
                {
                    case 1:
                        //1、添加学生信息
                        Test01(ref list);
                        break;
                    case 2:
                        //2、查询学生信息
                        Test02(list);
                        break;
                    case 3:
                        //3、删除学生信息
                        Test03(ref list);
                        break;
                    default:
                        break;
                }
            }
        }
        public static void Test01(ref List<Student> list)
        {
            //1、添加学生信息
            Console.WriteLine("请输入添加的学号");
            int num = int.Parse(Console.ReadLine());
            Boolean boo = false;
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].num == num)
                {
                    boo = true;
                }
            }
            if (boo)
            {
                Console.WriteLine("已存在该学号");
            }
            else
            {
                Console.WriteLine("请输入添加的姓名");
                string name = Console.ReadLine();
                Console.WriteLine("请输入添加的年龄");
                int age = int.Parse(Console.ReadLine());
                Student stu6 = new Student(num, name, age);
                list.Add(stu6);
            }
        }
        public static void Test02(List<Student> list)
        {
            //2、查询学生信息
            while (true)
            {
                Console.WriteLine("1、查询所有（按学号排序）2、查询所有（按姓名排序）3、查询所有（按年龄排序）4、按学号查询 5、退出");
                int key = int.Parse(Console.ReadLine());
                switch (key)
                {
                    case 1:
                        list.Sort(new Num());
                        for (int i = 0; i < list.Count; i++)
                        {
                            Console.WriteLine(list[i]);
                        }
                        break;
                    case 2:
                        list.Sort(new Name());
                        for (int i = 0; i < list.Count; i++)
                        {
                            Console.WriteLine(list[i]);
                        }
                        break;
                    case 3:
                        list.Sort(new Age());
                        for (int i = 0; i < list.Count; i++)
                        {
                            Console.WriteLine(list[i]);
                        }
                        break;
                    case 4:
                        Console.WriteLine("请输入要查询的学号");
                        int a = int.Parse(Console.ReadLine());
                        Boolean b = false;
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].num == a)
                            {
                                b = true;
                            }
                        }
                        if (b)
                        {
                            Console.WriteLine(list[a - 1]);
                        }
                        else
                        {
                            Console.WriteLine("没有该学号");
                        }
                        break;
                    case 5:
                        Process.GetCurrentProcess().Kill();
                        break;
                    default:
                        break;
                }
            }
        }
        public static void Test03(ref List<Student> list)
        {
            //3、删除学生信息
            Console.WriteLine("请输入你要删除第几个学生");
            int a = int.Parse(Console.ReadLine());
            list.RemoveAt(a - 1);
        }
    }
    class Student
    {
        public int num { get; set; }
        public string name { get; set; }
        public int age { get; set; }

        public Student(int num, string name, int age)
        {
            this.num = num;
            this.name = name;
            this.age = age;
        }

        public override string ToString()
        {
            return $"学号：{num},名字：{name},年龄：{age}";
        }
    }
    class Num : IComparer<Student>
    {
        public int Compare(Student x, Student y)
        {
            return x.num.CompareTo(y.num);
        }
    }
    class Name : IComparer<Student>
    {
        public int Compare(Student x, Student y)
        {
            return x.name.CompareTo(y.name);
        }
    }
    class Age : IComparer<Student>
    {
        public int Compare(Student x, Student y)
        {
            return x.age.CompareTo(y.age);
        }
    }
}